package com.example.rabbit.seven;

import com.example.rabbit.util.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import javafx.scene.transform.Scale;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * Topic主题订阅模式
 *
 * @Author ifredomvip@gmail.com
 * @Date 2022/8/9 9:34
 * @Version 1.0.0
 * @Description
 **/
public class EmitLogTopic {
    public static String exchangeName = "Topic-logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(exchangeName, BuiltinExchangeType.TOPIC);


        Map<String, String> bindingKeyMap = new HashMap<>();
        bindingKeyMap.put("quick.orange.rabbit", "被队列Q1Q2接收到");
        bindingKeyMap.put("lazy.orange.elephant", "被队列Q1Q2接收到");
        bindingKeyMap.put("quick.orange.fox", "被队列Q1接收到");
        bindingKeyMap.put("lazy.brown.fox", "被队列Q2接收到");
        bindingKeyMap.put("lazy.pink.rabbit", "只被队列Q2接受一次");
        bindingKeyMap.put("quick.brown.fox", "不匹配，被丢弃");
        bindingKeyMap.put("quick.orange.male.rabbit", "四个单词，不匹配，被丢弃");
        bindingKeyMap.put("lazy.orange.male.rabbit", "四个单词，但是匹配Q2，被Q2接收");

        for (Map.Entry<String, String> stringBindingKeyEntry : bindingKeyMap.entrySet()) {
            String key = stringBindingKeyEntry.getKey();
            String message = stringBindingKeyEntry.getValue();
            channel.basicPublish(exchangeName, key, null, message.getBytes());
        }


    }
}
